package www.lagou.dao;

import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanListHandler;
import www.lagou.entity.Phone;
import www.lagou.utils.DruidUtils;

import java.sql.SQLException;
import java.util.List;

public class PhoneDao {

    public void selectByPrice() throws SQLException {
        QueryRunner qr=new QueryRunner(DruidUtils.getDataSource());

        String sql="select * from phone where price > ? and prodate < ?";
        Object[] param={2000,"2019-01-01"};
        List<Phone> list =qr.query(sql, new BeanListHandler<Phone>(Phone.class), param);
        System.out.println("价格高于2000元，生产日期是2019年之前的手机有：");
        for (Phone phone : list) {
            System.out.println(phone);
        }

    }

    public void selectByColor() throws SQLException {
        QueryRunner qr=new QueryRunner(DruidUtils.getDataSource());

        String sql="select * from phone where color like ?";
        List<Phone> list =qr.query(sql, new BeanListHandler<Phone>(Phone.class), "%白色%");
        System.out.println("颜色是白色的手机有：");
        for (Phone phone : list) {
            System.out.println(phone);
        }
    }
}
